.TH std::ranges::views::join,std::ranges::join_view 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ranges::views::join,std::ranges::join_view \- std::ranges::views::join,std::ranges::join_view

.SH Synopsis
   Defined in header <ranges>
   template< ranges::input_range V >

       requires ranges::view<V> and
                ranges::input_range<ranges::range_reference_t<V>>   \fB(1)\fP \fI(since C++20)\fP
   class join_view

       : public ranges::view_interface<join_view<V>>
   namespace views {

       inline constexpr /* unspecified */ join = /* unspecified */; \fB(2)\fP \fI(since C++20)\fP

   }

   1) A range adaptor that represents view consisting of the sequence obtained from
   flattening a view of ranges.
   2) RangeAdaptorObject (and also RangeAdaptorClosureObject). The expression
   views::join(e) is expression-equivalent to join_view<views::all_t<decltype((e))>>{e}
   for any suitable subexpressions e.

   join_view models input_range.

   join_view models forward_range when:

     * ranges::range_reference_t<V> is a reference type, and
     * V and ranges::range_reference_t<V> each model forward_range.

   join_view models bidirectional_range when:

     * ranges::range_reference_t<V> is a reference type,
     * V models bidirectional_range, and
     * ranges::range_reference_t<V> models both bidirectional_range and common_range.

   join_view models common_range when:

     * ranges::range_reference_t<V> is a reference type, and
     * V and ranges::range_reference_t<V> each model forward_range and common_range.

.SH Member functions

   constructor   constructs a join_view
   (C++20)       \fI(public member function)\fP
   base          returns a copy of the underlying (adapted) view
   (C++20)       \fI(public member function)\fP
   begin         returns an iterator to the beginning
   (C++20)       \fI(public member function)\fP
   end           returns an iterator or a sentinel to the end
   (C++20)       \fI(public member function)\fP
         Inherited from std::ranges::view_interface
   empty         returns whether the derived view is empty. Provided if it satisfies
   (C++20)       sized_range or forward_range.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   cbegin        returns a constant iterator to the beginning of the range.
   (C++23)       \fI(public member function of std::ranges::view_interface<D>)\fP
   cend          returns a sentinel for the constant iterator of the range.
   (C++23)       \fI(public member function of std::ranges::view_interface<D>)\fP
   operator bool returns whether the derived view is not empty. Provided if
   (C++20)       ranges::empty is applicable to it.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   front         returns the first element in the derived view. Provided if it
   (C++20)       satisfies forward_range.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   back          returns the last element in the derived view. Provided if it satisfies
   (C++20)       bidirectional_range and common_range.
                 \fI(public member function of std::ranges::view_interface<D>)\fP

   Deduction guides

   Nested classes

   iterator the iterator type
   (C++20)  (exposition-only member class template*)
   sentinel the sentinel type
   (C++20)  (exposition-only member class template*)

.SH Notes

   Before P2328R1 was adopted, the inner range type (ranges::range_reference_t<V>)
   cannot be a container type (but can be reference to container). For example, it was
   not allowed to join a transform_view of std::string prvalue.

 struct Person { int age; std::string name; };

 auto f(std::vector<Person>& v) {
 //  return v | std::views::transform([](auto& p){ return p.name; })
 //           | std::views::join; // error before P2328R1
     return v | std::views::transform([](auto& p) -> std::string& { return p.name; })
              | std::views::join; // OK
 }

.SH Example


// Run this code

 #include <iostream>
 #include <ranges>
 #include <string_view>
 #include <vector>

 int main()
 {
     using namespace std::literals;

     const auto bits = {"https:"sv, "//"sv, "cppreference"sv, "."sv, "com"sv};
     for (char const c : bits | std::views::join)
         std::cout << c;
     std::cout << '\\n';

     const std::vector<std::vector<int>> v{{1, 2}, {3, 4, 5}, {6}, {7, 8, 9}};
     auto jv = std::ranges::join_view(v);
     for (int const e : jv)
         std::cout << e << ' ';
     std::cout << '\\n';
 }

.SH Output:

 https://cppreference.com
 1 2 3 4 5 6 7 8 9

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to             Behavior as published              Correct behavior
   LWG 3474 C++20      views::join(e) returned a copy of e when e is  returns a nested
                       a join_view                                    join_view
   P2328R1  C++20      non-view range prvalues could not be joined by made joinable
                       join_view

.SH See also

   ranges::join_with_view  a view consisting of the sequence obtained from flattening a
   views::join_with        view of ranges, with the delimiter in between elements
   (C++23)                 \fI(class template)\fP (range adaptor object)
   ranges::split_view      a view over the subranges obtained from splitting another
   views::split            view using a delimiter
   (C++20)                 \fI(class template)\fP (range adaptor object)
   ranges::lazy_split_view a view over the subranges obtained from splitting another
   views::lazy_split       view using a delimiter
   (C++20)                 \fI(class template)\fP (range adaptor object)
